﻿<?php

class AController extends Controller
{
	public function actionIndex()
	{
		$criteria = new CDbCriteria(array(
			'order'=>'article_createtime desc',
			'limit'=>'1000',
			'join'=>'left join article_sort on  t.article_sort_id = article_sort.article_sort_id',
			'with'=>'sortName',
			));
		if(isset($_GET['sign']))
        {
        	$sign = $_GET['sign'];
        	switch ($sign) {
        		case 'autited':
        			$criteria->addCondition('article_status = 1');
        			break;
        		case 'unAutited':
        			$criteria->addCondition('article_status = 0');
        			break;
        		case 'tursh':
        			$criteria->addCondition('article_status = 3');
        			break;
        		default:
        			$criteria->addCondition('article_status = 1');
        			break;
        		}
        }else{
        	$criteria->addCondition('article_status = 1');
        }

        $dataProvider = new CActiveDataProvider('ArticleList',array(
        	'criteria'=>$criteria,
        	'pagination'=>array(
        		'pagesize'=>'20',
        		),
        	));

		$this->render('index',array(
			'dataProvider'=> $dataProvider,
			));
	}

	public function actionCurd()
    {
    	if(Yii::app()->request->isAjaxRequest)
    	{
    		$sign = $_POST['sign'];
    		$article_id = $_POST['articleId'];
    				$article = ArticleList::model()->find('article_id=:article_id',array(':article_id'=>$article_id));
    		switch ($sign) {
    			case 'trash':
    				$article->article_status = 3;
    				$article->save();
    				break;
    			case 'delete':
   					$article->delete();
    				break;
    			case 'autited':
    				$article->article_status = 1;
    				$article->save();
    				break;
    			case 'recover':
					$article->article_status = 1;
					$article->save();		
    				break;
    			default:
    				return 'error';
    				break;
    		}
    	}
    }

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}